package com.example.guavaretry.test.service;

import com.github.rholder.retry.RetryException;
import com.github.rholder.retry.Retryer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;

@Service
public class RetryService {
    @Autowired
    private Retryer<Boolean> retryer;

    public void test(String p){
        try {
            retryer.call(retryTestCall(p));
        } catch (ExecutionException | RetryException e) {
            e.printStackTrace();
        }
    }

    private Callable<Boolean> retryTestCall(String p){
        return () -> {
            System.out.println(exec(p));
            return false;
        };
    }

    private String exec(String p){
        return "我被执行了，我是-" + p;
    }
}
